function DailyFaultManException() {
	var divId = "affectObjDiv";
	var currentItem = "";
	var util = new DailyUtil();
	var mans = {
		run : new RunMan(),
		alarm : new AlarmMan(),
		defect : new DefectMan(),
		overhaul : new OverhaulMan(),
		risk : new RiskMan(),
		newequipment : new NewEquipmentMan(),
		special : new SpecialReportMan(),
		historyFault : new HistoryFaultFeedBackMan()
	};
	//开始时间
	var start = '';
	//结束时间
	var end = '';
	//获得初始化开始时间、结束时间
	getDefaultDays();
	this.getStart = function() {
		return start;
	};
	this.getEnd = function() {
		return end;
	};
	this.show = function(item) {
		currentItem = item;
		clearAll();
		mans[currentItem].show();
	};
	this.zoom = function(level) {
		if (mans[currentItem].zoom) {
			mans[currentItem].zoom(level);
		}
	};
	this.clear = function() {
		$('#' + divId).css('display', 'none');
		if (mans[currentItem].clear) {
			mans[currentItem].clear();
		}
	};
	this.openPop = function(group, type, value) {
		mans[group].openPop(type, value);
	};
	this.openDialog = function(group, type, value) {
		mans[group].openDialog(type, value);
	};
	this.query = function() {
		var sval = $('#start').val();
		var eval = $('#end').val();
		var s = new Date(sval);
		var e = new Date(eval);
		// 将空的和不对的补齐
		if (!sval || s.toString() == 'Invalid Date') {
			$('.ice-warning-start').val(start);
			s = new Date(start);
		} else {
			start = sval;
		}
		if (!eval || e.toString() == 'Invalid Date') {
			$('.ice-warning-end').val(en);
			e = new Date(end);
		} else {
			end = eval;
		}
		if (s && e) {
			var gap = e.getTime() - s.getTime();
			if (!queryGap) {
				$.ajaxSettings.async = false;
				$.getJSON("/rest/getDailyReportQueryMaxDay", function(result) {
					queryGap = Number(result.day);
				});
				$.ajaxSettings.async = true;
			}
			if (gap > queryGap * 24 * 3600 * 1000) {
				$("#dailyQueryError").html(
						localeTitle.ChaXunShiJianBuChaoGuo + queryGap
								+ localeTitle.Tian + "！");
				$("#dailyQueryError").collapse('show');
			} else if (gap < 0) {
				$("#dailyQueryError").html(
						localeTitle.ChaXunKaiShiShiJianBuChaoGuoJieShuShiJian
								+ "！");
				$("#dailyQueryError").collapse('show');
			} else {
				$("#dailyQueryError").collapse('hide');
				mans[currentItem].query();
			}
		} else {
			$("#dailyQueryError").html(
					localeTitle.ChaXunShiJianBuBiaoZhun + "！");
			$("#dailyQueryError").collapse('show');
		}
	};
	this.dateMinus = function() {
		// var str = $('#start').val().substring(0,10);
		var str = $('#start').val();
		var ymd = str.split('-');
		var d = new Date(str);
		d.setFullYear(ymd[0], ymd[1] - 1, ymd[2] - 1);
		var m = d.getMonth() + 1 > 9 ? d.getMonth() + 1 : '0'
				+ (d.getMonth() + 1);
		var day = d.getDate() > 9 ? d.getDate() : '0' + d.getDate();
		// var dStr = d.getFullYear() + "-" + m + "-" + day+" 00:00:00";
		var dStr = d.getFullYear() + "-" + m + "-" + day;
		$('#start').val(dStr);
	};
	this.changeDate = function(end, start) {
		var s = new Date();
		var e = new Date();
		s.setDate(s.getDate() + start);
		s.setHours(0, 0, 0, 0);
		e.setDate(e.getDate() + end);
		e.setHours(23, 59, 59, 999);
		start = util.getDayTimeStr(s.getTime());
		end = util.getDayTimeStr(e.getTime());
		$('#start').val(start);
		$('#end').val(end);
		this.query();
	};

	/**
	 * 初始化查询日期
	 */
	function getDefaultDays() {
		var s = new Date();
		var e = new Date();
		if (s.getDay() == 1) {
			s.setDate(s.getDate() - 3);
		} else {
			s.setDate(s.getDate() - 1);
		}
		s.setHours(0, 0, 0, 0);
		e.setDate(e.getDate() - 1);
		e.setHours(23, 59, 59, 999);
		start = util.getDayTimeStr(s.getTime());
		end = util.getDayTimeStr(e.getTime());
		// 演示方便暂时添加
		// start='2017-09-26';
		// end='2017-09-27';
	}

	/**
	 * 故障日报
	 */
	function RunManReplace() {
		var divId = "affectObjDiv";
		var divTitle = localeTitle.daily.GuZhangRiBao;
		var util = new DailyUtil();
		var panels = new PanelTablesUtil(divId);
		//是否显示
		var isShow = false;
		var runs = {
			fault : []
		};
		var equipments = {
			fault : []
		};
		var processPop = undefined;

		this.show = function() {
			isShow = true;
			initData();
		};
		//查询方法
		this.query = function() {
			clearAll();
			isShow = true;
			initData();
		};
		//打开dialog
		this.openDialog = function(type, value) {
			if (type == 'interrupt') {
				var url = '/ui/map/dialog/daily/dailyInterruptAlarm.xhtml';
				util.openDialogWithTimeParamter(url, {
					stationId : value
				});
			} else if (type == 'interruptList') {
				var url = "/ui/map/dialog/daily/dailyInterruptAlarm.xhtml";
				util.openDialogWithTimeParamter(url);
			} else if (type == 'doubleList') {
				var url = "/ui/map/dialog/daily/dailyDoubleChannelInterruptAlarm.xhtml";
				util.openDialogWithTimeParamter(url);
			} else if (type == 'frequentlyList') {
				var url = "/ui/map/dialog/daily/dailyFrequentlyInterruptAlarm.xhtml";
				util.openDialogWithTimeParamter(url);
			}
		};
		//加载数据
		function initData() {
			var start = dailyFaultMan.getStart();
			var end = dailyFaultMan.getEnd();
			$.ajaxSettings.async = false;
			//保护告警模块-----地图使用的中断告警，添加了lon，lat字段
			$.getJSON("/rest/protectAlarm/getMapProtectInterruptAlarm/" + start + "/" + end, function(result) {
				alarms.interrupt = result;
				alarms.interrupt.sort(sortAlarm);
				var res = util.loadMapAndEquip(alarms.interrupt, [ 'lon', 'lat', 'stationName' ], {
					'stationId' : 'stationId'
				}, 'stationName');
				lonlatMaps.interrupt = res.map;
				equipments.interrupt = res.equipment;
			});
			$.getJSON("/rest/protectAlarm/getMapFrequentProtectInterruptAlarm/" + start + "/" + end, function(result) {
				alarms.frequently = result;
			});
			$.getJSON("/rest/protectAlarm/getMapFrequentDoubleChannelAlarm/" + start + "/" + end, function(result) {
				alarms.double = result;
			});
			$.ajaxSettings.async = true;
			show();
		}
		
		function show() {
			panels = new PanelTablesUtil(divId);
			panels.setTitle("<span>" + divTitle + "  <small style=\"color:#A6A6A6\">" + localeTitle.daily.BaoHuRiBao
					+ "</small></span>");
			panels.setInfo(util.getQueryDiv());
			addInterruptDiv(panels);
			addFrequentlyDiv(panels);
			addDoubleDiv(panels);
			panels.show();
			for ( var i in alarms) {
				length += alarms[i].length;
			}
			if (length > 0) {
				panels.setDangerBox();
			} else {
				panels.setSuccessBox();
			}
			util.setQueryTimePicker();
		}
		
		function addInterruptDiv(panels) {
			var expand = false;
			// var expand = currentType == 'interrupt';
			var clickListener = 'dailyFaultMan.onPanelClick(\'interrupt\');';
			var openList = 'dailyFaultMan.openDialog("alarm","interruptList")';
			var title = interruptTitle;
			var sub = "<span style='color:gray;' onclick='" + openList + "' class='pull-right'>" + localeTitle.mingXi
			+ "</span>";
			if (alarms.interrupt.length > 0) {
				title += "<span title='保护通信中断个数' onclick='" + openList + "' class='badge bg-red pull-right'>"
				+ alarms.interrupt.length + "</span>";
				title += sub;
				var ele = panels.getCollapsePanelEle("dailyInterruptDiv", title, expand, clickListener);
				// pie图数据
				var counts = {
						interrupt : 0,
						other : 0
				};
				var durationTimes = {
						interrupt : 0,
						other : 0
				};
				for ( var i in alarms.interrupt) {
					var r = alarms.interrupt[i];
					if (r.channelAlarms && r.channelAlarms.length > 0) {
						counts.interrupt++;
						durationTimes.interrupt += (r.durationTime ? r.durationTime : 0);
					} else {
						counts.other++;
						durationTimes.other += (r.durationTime ? r.durationTime : 0);
					}
				}
				var time = ((durationTimes.interrupt + durationTimes.other) / 1000 / 3600).toFixed(2);
				ele.append("<span style='margin-left:15px;'>"+localeTitle.channel.BaoHuTongXiZhongDuanFaSheng+"<span style='color:red;font-size:20px;'> "
						+ alarms.interrupt.length +" </span>"+localeTitle.channel.Ci+"，"+localeTitle.channel.GongJi+"<span style='color:red;font-size:20px;'> " + time
						+ " </span>"+localeTitle.channel.XiaoShi+"</span>");
				var pieDiv = $('<div id="dailyInterruptPie" style="height:150px;width:300px;" ></div>');
				ele.append(pieDiv);
				var color1 = '#dd4b39';
				var color2 = 'cadetblue';
				var pie = echarts.init(pieDiv[0]);
				var data1 = [];
				data1.push({
					name : '通信通道中断',
					value : counts.interrupt,
					itemStyle : {
						normal : {
							color : color1
						}
					}
				});
				if (counts.other > 0) {
					data1.push({
						name : '保护通道中断',
						value : counts.other,
						label : {
							normal : {
								show : false
							},
							emphasis : {
								show : false
							}
						},
						labelLine : {
							normal : {
								show : false
							},
							emphasis : {
								show : false
							}
						},
						itemStyle : {
							normal : {
								color : color2
							}
						}
					});
				}
				var option = {
						series : [ {
							name : '通信中断次数',
							type : 'pie',
							center : [ '50%', '50%' ],
							radius : '60%',
							minAngle : 5,
							label : {
								normal : {
									formatter : '{b}\n{c}次'
								}
							},
							data : data1
						} ]
				};
				pie.setOption(option);
			} else {
				title += sub;
				var ele = panels.getCollapsePanelEle("dailyInterruptDiv", title, expand, clickListener);
				ele.append(PanelTablesUtil.getSmileInfo(localeTitle.channel.WuTongXinZhongDuanYiChang));
			}
		}
		function addFrequentlyDiv(panels) {
			var expand = false;
			var clickListener = 'dailyFaultMan.onPanelClick(\'frequently\');';
			var tableId = 'dailyFrequentlyTable';
			var openlist = 'dailyFaultMan.openDialog("alarm","frequentlyList")';
			var title = frequentlyTitle;
			if (alarms.frequently.length > 0) {
				title += "<span title='" + frequentlyTitle + "次数' onclick='" + openlist
				+ "' class='badge bg-red pull-right'>" + alarms.frequently.length + "</span>";
				title += "<span style='color:gray;' onclick='" + openlist + "' class='pull-right'>" + localeTitle.mingXi
				+ "</span>";
				var tablediv = panels.drawCollapseTable(tableId, title, expand, clickListener);
				var columns = [ localeTitle.channel.XianLu,localeTitle.channel.BaoHu , localeTitle.channel.PinFanCiShu];
				var opt = util.getTableOption();
				opt.orderFixed = [ [ 0, 'asc' ] ];
				var table = new MyTable(tablediv, columns, opt);
				var dataset = [];
				for ( var i in alarms.frequently) {
					var f = alarms.frequently[i];
					dataset.push([ f.lineName, f.protectType, f.alarms.length ]);
				}
				table.setDataSet(dataset);
				table.show();
				table.onRowClick(function(data) {
					if (data) {
						$("#input_search").val(data[0]);
						searchObj(true);
					}
				});
			} else {
				title += "<span style='color:gray;' onclick='" + openlist + "' class='pull-right'>" + localeTitle.mingXi
				+ "</span>";
				var ele = panels.getCollapsePanelEle(tableId + "Div", title, expand, clickListener);
				ele.append(PanelTablesUtil.getSmileInfo(localeTitle.channel.WeiFaShengBaoHuTongDaoPinFanZhongDuan));
			}
		}
		function addDoubleDiv(panels) {
			var expand = false;
			var clickListener = 'dailyFaultMan.onPanelClick(\'double\');';
			var openList = 'dailyFaultMan.openDialog("alarm","doubleList")';
			var tableId = 'dailyDoubleTable';
			var title = doubleTitle;
			if (alarms.double.length > 0) {
				title += "<span title='" + doubleTitle + "次数' onclick='" + openList + "' class='badge bg-red pull-right'>"
				+ alarms.double.length + "</span>";
				title += "<span style='color:gray;' onclick='" + openList + "' class='pull-right'>" + localeTitle.mingXi
				+ "</span>";
				var tablediv = panels.drawCollapseTable(tableId, title, expand, clickListener);
				var columns = [ localeTitle.channel.XianLu, localeTitle.channel.BaoHu, localeTitle.channel.ShiJian ];
				var opt = util.getTableOption();
				opt.order = [ [ 0, 'asc' ], [ 1, 'asc' ] ];
				var table = new MyTable(tablediv, columns, opt);
				var dataset = [];
				for ( var i in alarms.double) {
					var f = alarms.double[i];
					dataset.push([ f.lineName, f.protectType, (f.continueMs / 60000).toFixed(2) + '分钟' ]);
				}
				table.setDataSet(dataset);
				table.show();
				table.onRowClick(function(data) {
					if (data) {
						$("#input_search").val(data[0]);
						searchObj(true);
					}
				});
			} else {
				title += "<span style='color:gray;' onclick='" + openList + "' class='pull-right'>" + localeTitle.mingXi
				+ "</span>";
				var ele = panels.getCollapsePanelEle(tableId + "Div", title, expand, clickListener);
				ele.append(PanelTablesUtil.getSmileInfo(localeTitle.channel.WeiFaShengShuangTongDaoTongShiZhongDuan));
			}
		}
	}
	
	/**
	 * 保护缺陷
	 */
	function DefectManReplace() {
		var util = new DailyUtil();
		var defects = undefined; // 保护缺陷及处理情况
		var divId = 'affectObjDiv';
		var panels = new PanelTablesUtil(divId);
		var divTitle = localeTitle.daily.BaoHuQueXian;
		var popMap = {
				defect : new Map()
		};
		var lonlatMaps = {
				defect : new Map()
		};
		this.show = function() {
			initData();
		};
		this.query = function() {
			clearAll();
			initData();
		};
		this.openPop = function(type, value) {
			// 添加保护缺陷弹窗
			var pop = popMap[type].get(value.stationId);
			if (pop) {
				if (pop.isShow()) {
					pop.remove();
				} else {
					pop.show();
				}
			}
		};
		this.openDialog = function(type, value) {
			if (type == "detail") {
				var url = '/ui/map/dialog/daily/dailyDefect.xhtml';
				util.openDialogWithTimeParamter(url, {
					stationId : value
				});
			}
			if (type == "list") {
				var url = '/ui/map/dialog/daily/dailyDefect.xhtml';
				util.openDialogWithTimeParamter(url);
			}
		};
		function initData() {
			var start = dailyFaultMan.getStart();
			var end = dailyFaultMan.getEnd();
			$.getJSON("/rest/protectDefect/getProtectDefect/" + start + "/" + end, function(result) {
				result.sort(sortTime);
				defects = result;
				var res = util.loadMapAndEquip(defects, [ 'lon', 'lat', 'substationName' ], {
					'stationId' : 'substationId'
				}, 'substationName');
				lonlatMaps.defect = res.map;
				show();
			});
		}
		function sortTime(obj1, obj2) {
			if (obj1.startTime < obj2.startTime) {
				return 1;
			} else {
				return -1;
			}
		}
		function show() {
			showDiv();
			addDefectPops();
		}
		function showDiv() {
			panels = new PanelTablesUtil(divId);
			panels.setTitle("<span>" + divTitle + "  <small style=\"color:#A6A6A6\">" + localeTitle.daily.BaoHuRiBao
					+ "</small></span>");
			panels.setInfo(util.getQueryDiv());
			addDefectDiv(panels);
			panels.show();
			util.setQueryTimePicker();
		}
		function addDefectDiv(panels) {
			var expand = true;
			var tableId = "dailyDefectTable";
			var title = localeTitle.daily.BaoHuQueXianJiChuLi;
			var openList = 'dailyFaultMan.openDialog("defect","list")';
			var sub = "<span class='pull-right' style='color:gray;' onclick='" + openList + "'>" + localeTitle.mingXi
			+ "</span>";
			if (defects.length > 0) {
				panels.setDangerBox();
				var dataset = util.getDataset(defects, [ 'substationName', 'protectType', {
					value : 'protectQuitTime',
					type : 'secondTimeStr'
				} ]);
				title += "<span title='保护缺陷个数' onclick='" + openList + "' class='badge bg-red pull-right'>"
				+ defects.length + "</span>";
				var tablediv = panels.drawCollapseTable(tableId, title + sub, expand);
				var option = util.getTableOption();
				var columns = [ localeTitle.defect.ChangZhanMingCheng, localeTitle.defect.BaoHuMingCheng, localeTitle.defect.BaoHuTuiChuShiJian ];
				var table = new MyTable(tablediv, columns, option);
				table.setDataSet(dataset).show();
				table.onRowClick(function(data) {
					if (data) {
						$("#input_search").val(data[0]);
						searchObj(true);
					}
				});
			} else {
				panels.setSuccessBox();
				title += sub;
				var ele = panels.getCollapsePanelEle(tableId, title, expand);
				ele.append(PanelTablesUtil.getSmileInfo(localeTitle.defect.WuQueXianJiLu));
			}
		}
		function addDefectPops() {
			var map = new Map();
			for ( var i in defects) {
				var d = defects[i];
				var ds = map.get(d.lon + ',' + d.lat + ',' + d.substationId);
				if (!ds) {
					ds = [];
					map.put(d.lon + ',' + d.lat + ',' + d.substationId, ds);
				}
				ds.push(d);
			}
			popMap.defect.clear();
			map.each(function(index, key, value) {
				var pop = getDefectPop(key, value);
				// pop.show();
				popMap.defect.put(value[0].substationId, pop);
			});
		}
		function getDefectPop(lonlat, ds) {
			lonlat = lonlat.split(",");
			var pop = new Popup(lonlat[0], lonlat[1]);
			var listener = 'dailyFaultMan.openDialog("defect","detail","' + lonlat[2] + '")';
			pop.setTitle(ds[0].substationName).setTitleIconClickListener(listener).setTitleSelfClickListener(listener);
			for ( var i in ds) {
				var d = ds[i];
				pop.setRowContent(d.defectDescription).setRowClickListener(listener);
			}
			return pop;
		}
	}
	
	/**
	 * 保护检修
	 */
	function OverhaulManReplace() {
		var divId = "affectObjDiv";
		var util = new DailyUtil();
		var currentPop = undefined;
		var overhauls = {
				todo : undefined,
				doing : undefined,
				done : undefined
		};
		var lonlatMaps = {
				todo : new Map(),
				doing : new Map(),
				done : new Map()
		};
		var equipments = {
				todo : [],
				doing : [],
				done : []
		};
		var popMap = {
				todo : new Map(),
				doing : new Map(),
				done : new Map()
		};
		var selectedTypes = {
				todo : false,
				doing : false,
				done : true
		};

		this.show = function() {
			initData();
		};
		this.query = function() {
			clearAll();
			initData();
		};
		this.onPanelClick = function(type) {
			selectedTypes[type] = !selectedTypes[type];
			showPoints();
		};
		function showPoints() {
			selectedLayer.removeAllFeatures();
			weatherLayer.removeAllFeatures();
			map.removeAllPopup();
			for ( var item in selectedTypes) {
				if (selectedTypes[item]) {
					util.markPoint(lonlatMaps[item], "/resources/img/daily/" + item + ".gif", 'overhaul', item);
					util.markLines(equipments[item]);
					$('#' + item + 'StatusIcon').addClass("text-red");
				} else {
					$('#' + item + 'StatusIcon').removeClass("text-red");
				}
			}
		}
		this.openDialog = function(type, value) {
			var url = "/ui/map/dialog/daily/dailyOverhaul.xhtml";
			if (type == "detail") {
				util.openDialogWithTimeParamter(url, {
					stationId : value
				});
			}
			if (type == "list") {
				util.openDialogWithTimeParamter(url);
			}
		};
		this.openPop = function(type, value) {
			var pop = popMap[type].get(value.stationIdOrAreaValue);
			if (pop.isShow()) {
				pop.remove();
				currentPop = undefined;
			} else {
				if (currentPop) {
					currentPop.remove();
				}
				pop.show();
				currentPop = pop;
			}
		};
		function initData() {
			var start = dailyFaultMan.getStart();
			var end = dailyFaultMan.getEnd();
			$.getJSON("/rest/protectOverhaul/getMapProtectOverhaul/"+start+"/"+end, function(result) {
				overhauls.todo = result.todo;
				overhauls.doing = result.doing;
				overhauls.done = result.done;
				for ( var i in overhauls) {
					var res = util.loadMapAndEquip(overhauls[i], [ 'lon', 'lat', 'station_name' ], {
						stationIdOrAreaValue : 'station_id'
					}, 'station_name');
					lonlatMaps[i] = res.map;
					equipments[i] = res.equipment;
				}
				show();
			});
		}
		function show() {
			showDiv();
			showPoints();
		}
		function showDiv() {
			var panel = new PanelTablesUtil(divId);
			panel.setTitle("<span>" + localeTitle.daily.BaoHuJianXiu + "  <small style=\"color:#A6A6A6\">"
					+ localeTitle.daily.BaoHuRiBao + "</small></span>");
			panel.setInfo(util.getQueryDiv());
			if ((!overhauls.todo || overhauls.todo.length == 0 )
					&& (!overhauls.doing || overhauls.doing.length == 0) 
					&& (!overhauls.done || overhauls.done.length == 0)) {
				panel.setSuccessBox();
				panel.setInfo(PanelTablesUtil.getSmileInfo("无检修计划"));
			} else {
				panel.setDangerBox();
				addPanelInfo(panel);
				addOverhaulPops('todo');
				addOverhaulPops('doing');
				addOverhaulPops('done');
			}
			panel.show();
			util.setQueryTimePicker();
		}
		function addPanelInfo(panel) {
			var info = $('<table class="table table-hover" style="width:100%"></table>');
			info.append(getImage('overhaul', '全部', 'brown'));
			info.append(getImage('done', '已完工', 'green'));
			info.append(getImage('doing', '进行中', 'blue'));
			info.append(getImage('todo', '待开工', 'orange'));
			panel.setInfo(info);
			function getEnglishName(name) {
				var engName = "";
				if (name == '全部') {
					engName = localeTitle.daily.QuanBu;
				} else if (name == '已完工') {
					engName = localeTitle.daily.YiWanGong;
				} else if (name == '进行中') {
					engName = localeTitle.daily.JinXingZhong;
				} else if (name == '待开工') {
					engName = localeTitle.daily.DaiKaiGong;
				}
				return engName;
			}
			function getImage(type, name, color) {
				var listener = 'dailyFaultMan.onPanelClick(\'' + type + '\')';
				if (name == '全部') {
					listener = "dailyFaultMan.openDialog('overhaul','list')";
				}
				var div = '<div style="cursor:pointer;" onclick="' + listener + '">';
				var img = '<img src="/resources/img/daily/' + type + '.gif" style="width:30px;height:30px;" alt="' + name
				+ '"> <img>';
				var item = '<span>' + getEnglishName(name) + '</span>';
				if (name == '待开工') {
					var now = new Date();
					item = '<span>' + localeTitle.daily.JieZhi + '<span style="font-size:18px;">'
					+ util.getDayTimeStr(now.getTime()) + '</span>,' + localeTitle.daily.DaiKaiGong + '<span>';
				}
				var num = '';
				var map = '';
				if (name == '全部') {
					var length = 0;
					for ( var i in overhauls) {
						if (overhauls[i]) {
							length += overhauls[i].length;
						}
					}
					num = '<span style="margin:5px;font-size:25px;color:' + color + ';">' + length + '</span>';
					map = '<span class="pull-right" style="margin-right:20px;color:gray;">' + localeTitle.mingXi
					+ '</span>';
				} else {
					num = '<span style="margin:5px;font-size:25px;color:' + color + ';">' + overhauls[type].length
					+ '</span>';
					map = '<span class="pull-right" style="margin-right:20px;"><i id="' + type
					+ 'StatusIcon" class="fa fa-map-marker"></i></span>';
				}
				return '<tr><td>' + div + img + item + num + map + '</div></td></tr>';
			}
		}
		function addTodoDiv(panel) {
			var expand = currentType == 'todo';
			var clickListener = 'dailyFaultMan.onPanelClick(\'todo\');';
			var tableId = 'dailyTodoTable';
			var title = localeTitle.daily.DaiKaiGong;
			if (overhauls.todo.length > 0) {
				var dataset = util.getDataset(overhauls.todo, [ 'station_name', 'content' ]);
				title += '<span class="badge bg-yellow pull-right" title="' + title + '计划数">' + dataset.length + '</span>';
				panel.drawCollapseTable(tableId, title, expand, clickListener);
				var option = util.getTableOption();
				option.columnDefs = [ {
					targets : 0,
					width : '33%'
				}, {
					targets : 1,
					width : '67%'
				} ];
				var columns = [ '检修地点', '检修内容' ];
				var table = new MyTable(tableId, columns, option);
				table.setDataSet(dataset);
				table.show();
				table.onRowClick(function(data) {
					if (data) {
						$("#input_search").val(data[0]);
						searchObj(true);
					}
				});
			} else {
				panel.getCollapsePanelEle(tableId + 'parent', title, expand, clickListener).append(
						PanelTablesUtil.getSmileInfo("无" + title + "计划"));
			}
		}
		function addDoingDiv(panel) {
			var expand = currentType == 'doing';
			var clickListener = 'dailyFaultMan.onPanelClick(\'doing\');';
			var tableId = 'dailyDoingTable';
			var title = localeTitle.daily.JinXingZhong;
			if (overhauls.doing.length > 0) {
				var dataset = util.getDataset(overhauls.doing, [ 'station_name', 'content' ]);
				title += '<span class="badge bg-blue pull-right" title="' + title + '计划数">' + dataset.length + '</span>';
				panel.drawCollapseTable(tableId, title, expand, clickListener);
				var option = util.getTableOption();
				option.columnDefs = [ {
					targets : 0,
					width : '33%'
				}, {
					targets : 1,
					width : '67%'
				} ];
				var columns = [ '检修地点', '检修内容' ];
				var table = new MyTable(tableId, columns, option);
				table.setDataSet(dataset);
				table.show();
				table.onRowClick(function(data) {
					if (data) {
						$("#input_search").val(data[0]);
						searchObj(true);
					}
				});
			} else {
				panel.getCollapsePanelEle(tableId + 'parent', title, expand, clickListener).append(
						PanelTablesUtil.getSmileInfo("无" + title + "计划"));
			}
		}
		function addDoneDiv(panel) {
			var expand = currentType == 'done';
			var clickListener = 'dailyFaultMan.onPanelClick(\'done\');';
			var tableId = 'dailyDoneTable';
			var title = localeTitle.daily.YiWanGong;
			var sub = '<span style="color:gray;" class="pull-right">昨日</span>';
			if (overhauls.done.length > 0) {
				var dataset = util.getDataset(overhauls.done, [ 'station_name', 'content' ]);
				title += '<span class="badge bg-green pull-right" title="' + title + '计划数">' + dataset.length + '</span>';
				title += sub;
				panel.drawCollapseTable(tableId, title, expand, clickListener);
				var option = util.getTableOption();
				option.columnDefs = [ {
					targets : 0,
					width : '33%'
				}, {
					targets : 1,
					width : '67%'
				} ];
				var columns = [ '检修地点', '检修内容' ];
				var table = new MyTable(tableId, columns, option);
				table.setDataSet(dataset);
				table.show();
				table.onRowClick(function(data) {
					if (data) {
						$("#input_search").val(data[0]);
						searchObj(true);
					}
				});
			} else {
				panel.getCollapsePanelEle(tableId + 'parent', title + sub, expand, clickListener).append(
						PanelTablesUtil.getSmileInfo("无" + title + "计划"));
			}
		}
		function addOverhaulPops(type) {
			var lonlats = new Map();
			for ( var i in overhauls[type]) {
				var v = overhauls[type][i];
				if (v.lon && v.lat) {
					var fs = lonlats.get(v.lon + ',' + v.lat);
					if (!fs) {
						fs = [];
						lonlats.put(v.lon + ',' + v.lat, fs);
					}
					fs.push(v);
				}
			}
			popMap[type].clear();
			lonlats.each(function(index, key, value) {
				var pop = undefined;
				switch (type) {
				case 'todo':
					pop = getTodoPop(value);
					break;
				case 'doing':
					pop = getDoingPop(value);
					break;
				case 'done':
					pop = getDonePop(value);
					break;
				}
				popMap[type].put(value[0]['station_id'], pop);
				// pop.show();
			});
		}
		function getTodoPop(value) {
			var pop = new Popup(value[0].lon, value[0].lat);
			var clickListener = 'dailyFaultMan.openDialog("overhaul","detail","' + value[0]['station_id'] + '");';
			pop.setTitle(value[0]['station_name']).setTitleIconClickListener(clickListener).setTitleSelfClickListener(
					clickListener);
			for ( var i in value) {
				pop.setRowContent(value[i].content).setRowClickListener(clickListener);
			}
			pop.setAutoSize(true);
			pop.showCloseIcon(true);
			return pop;
		}
		function getDoingPop(value) {
			var pop = new Popup(value[0].lon, value[0].lat);
			var clickListener = 'dailyFaultMan.openDialog("overhaul","detail","' + value[0]['station_id'] + '");';
			pop.setTitle(value[0]['station_name']).setTitleIconClickListener(clickListener).setTitleSelfClickListener(
					clickListener);
			for ( var i in value) {
				pop.setRowContent(value[i].content).setRowClickListener(clickListener);
			}
			pop.setAutoSize(true);
			pop.showCloseIcon(true);
			return pop;
		}
		function getDonePop(value) {
			var pop = new Popup(value[0].lon, value[0].lat);
			var clickListener = 'dailyFaultMan.openDialog("overhaul","detail","' + value[0]['station_id'] + '");';
			pop.setTitle(value[0]['station_name']).setTitleIconClickListener(clickListener).setTitleSelfClickListener(
					clickListener);
			for ( var i in value) {
				pop.setRowContent(value[i].content).setRowClickListener(clickListener);
			}
			pop.setAutoSize(true);
			pop.showCloseIcon(true);
			return pop;
		}
		
		function drawBar() {
			bar3DLayer.removeAllFeatures();
			weatherLayer.removeAllFeatures();
			bar3DLayer.setVisibility(true);
			bar3DLayer.div.style.zIndex = 400;
			var features = [];
			var labelFeas = [];
			var max = 5;
			exceedMap.each(function(index, key, value) {
				max = value.length > max ? value.length : max;
			});
			bar3DLayer.chartsSetting.codomain[1] = max;
			for ( var i in geos) {
				var details = [];
				exceedMap.each(function(index, key, value) {
					if (key.indexOf(geos[i][0]) > -1) {
						details = value;
					}
				});
				var geo = new SuperMap.Geometry.Point(geos[i][1], geos[i][2]);
				var attrs = {
						NAME : geos[i][0],
						NUM : details.length,
						TYPE : 'overhaul'
				};
				var fea = new SuperMap.Feature.Vector(geo, attrs);
				features.push(fea);
				labelFeas.push(markNameLabel(geo, geos[i][0]));
				labelFeas.push(markValueLabel(geo, details.length, max));
			}
			bar3DLayer.addFeatures(features);
			weatherLayer.addFeatures(labelFeas);
			weatherLayer.setVisibility(true);
		}
		function markValueLabel(geo, value, max) {
			var maxh = bar3DLayer.chartsSetting.height;
			var h = value * maxh / max;
			var style = {
					fill : 'red',
					label : value + "",
					labelXOffset : -5,
					labelYOffset : h + 15,
					fontColor : "red",
					fontOpacity : "0.8",
					fontSize : "2em",
					fontWeight : "bold",
					fontStyle : "italic"
			};
			var pointFeature = new SuperMap.Feature.Vector(geo, null, style);
			return pointFeature;
		}
		function markNameLabel(geo, name) {
			// 画一个label
			var style = {
					label : name,
					labelXOffset : -10,
					labelYOffset : -20,
					fontColor : "black",
					fontOpacity : "0.5",
					fontFamily : "隶书",
					fontSize : "3em",
					fontWeight : "bold",
					fontStyle : "italic"
			};
			var pointFeature = new SuperMap.Feature.Vector(geo, null, style);
			return pointFeature;
		}
	}
	/**
	 * 保护风险
	 */
	function RiskManReplace() {
		var util = new DailyUtil();
		this.show = function() {
			var url = '/ui/map/dialog/daily/dailyRiskDetail.xhtml';
			util.openDialogWithTimeParamter(url);
		};
	}
	function NewEquipmentManReplace() {
		var util = new DailyUtil();
		this.show = function() {
			var url = '/ui/map/dialog/daily/dailyNewEquipment.xhtml';
			util.openDialogWithTimeParamter(url);
		};
	}
	function SpecialReportManReplace() {
		var util = new DailyUtil();
		this.show = function() {
			var url = '/ui/map/dialog/daily/dailySpeicalReport.xhtml';
			util.openDialogWithTimeParamter(url);
		};
	}
	function HistoryFaultFeedBackManReplace() {
		var util = new DailyUtil();
		this.show = function() {
			var url = '/ui/map/dialog/daily/dailyHistoryFaultFeedback.xhtml';
			util.openDialogWithTimeParamter(url);
		};
	}
	
	/**
	 * 公用工具类
	 */
	function DailyUtilReplace() {
		var divId = 'affectObjDiv';
		this.getQueryDiv = function() {
			var start = dailyFaultMan.getStart();
			var end = dailyFaultMan.getEnd();
			var queryDiv = $('<div id="queryDiv" style="display:block"/>');
			queryDiv
			.html(
					'<div class="btn-group">'
					+ '<button class="btn btn-sm btn-flat btn-default" onclick="dailyFaultMan.changeDate(0,-1)">'+localeTitle.ZuoTian+'</button>'
					+ '<button class="btn btn-sm btn-flat btn-default" onclick="dailyFaultMan.changeDate(0,-3)">'+localeTitle.QianSanTian+'</button>'
					+ '<button class="btn btn-sm btn-flat btn-default" onclick="dailyFaultMan.changeDate(0,-4)">'+localeTitle.QianSiTian+'</button>'
					+ '<button class="btn btn-sm btn-flat btn-default" onclick="dailyFaultMan.changeDate(0,-8)">'+localeTitle.QianBaTian+'</button>'
					+ '</div>'
					+ '<div style="display:flex;">'
					+ '<button class="btn btn-flat btn-default" onclick="dailyFaultMan.dateMinus()"><i class="fa fa-arrow-left"></i></button>'
					+ '<input type="text" class="form-control" id="start" value="'
					+ start
					+ '" />'
					+ '<input type="text" class="form-control" id="end" value="'
					+ end
					+ '" />'
					+ '<button class="btn btn-flat btn-default" onclick="dailyFaultMan.query();">' + localeTitle.search
					+ '</button>' + '</div>'
					+ '<div id="dailyQueryError" class="collapse" style="color:red"></div>');
			return queryDiv;
		};
		this.setQueryTimePicker = function() {
			setTimePicker();
		};
		function setTimePicker() {
			var e = new Date();
			$('#start').datetimepicker({
				format : 'yyyy-mm-dd',
				minView : 2,
				autoclose : true,
				endDate : e,
				todayHighlight : true
			});
			$('#end').datetimepicker({
				format : 'yyyy-mm-dd',
				minView : 2,
				autoclose : true,
				endDate : e,
				pickerPosition : 'bottom-left',
				todayHighlight : true
			});
		}
		function appendQueryDiv(parent) {
			var start = dailyFaultMan.getStart();
			var end = dailyFaultMan.getEnd();
			var queryDiv = $('<div id="queryDiv" style="display:block"/>');
			queryDiv
			.html('<div class="input-group">'
					+ '<div class="input-group-btn">'
					+ '<button class="btn btn-default" onclick="dailyFaultMan.dateMinus()"><i class="fa fa-arrow-left"></i></button>'
					+ '</div>'
					+ '<input type="text" style="width:107px" class="form-control" id="start" value="'
					+ start
					+ '" />'
					+ '<input type="text" style="width:107px"  class="form-control" id="end" value="'
					+ end
					+ '" />'
					+ '<div class="input-group-btn">'
					+ '<button class="btn btn-default" onclick="dailyFaultMan.query();">' + localeTitle.search
					+ '</button>' + '</div>' + '</div>');
			parent.append(queryDiv);
			var e = new Date();
			e.setDate(e.getDate() - 1);
			$('#start').datetimepicker({
				format : 'yyyy-mm-dd',
				minView : 2,
				autoclose : true,
				endDate : e,
				todayHighlight : true
			});
			$('#end').datetimepicker({
				format : 'yyyy-mm-dd',
				minView : 2,
				autoclose : true,
				endDate : e,
				pickerPosition : 'bottom-left',
				todayHighlight : true
			});
			return queryDiv;
		}
		;
		this.getTableOption = function() {
			var opt = MyTable.getDefaultOptions();
			opt.scrollX = false;
			opt.autoWidth = false;
			opt.columnDefs = [ {
				"width" : "33%",
				"targets" : 0
			}, {
				"width" : "33%",
				"targets" : 1
			}, {
				"width" : "33%",
				"targets" : 2
			} ];
			opt.scrollY = 230;
			opt.scrollCollapse = true;
			return opt;
		};
		this.getFaultTableOption = function() {
			var opt = MyTable.getDefaultOptions();
			opt.scrollX = false;
			opt.autoWidth = false;
			opt.columnDefs = [ {
				"width" : "33%",
				"targets" : 0
			}, {
				"width" : "33%",
				"targets" : 1
			}, {
				"width" : "33%",
				"targets" : 2
			},{
				"targets" : 3,
				"visible":false
			} ];
			opt.scrollY = 230;
			opt.scrollCollapse = true;
			return opt;
		};
		this.commonPanelTable = function(parendId, titleName, columns, searchIndex, dataset, expand, clickListener, type,
				subTitle, subTitleClick) {
			var tbid = 'daily' + type + 'Table';
			var div = drawTablePanel(parendId, titleName, tbid, expand, clickListener, subTitle, subTitleClick);
			div.append('<table id=' + tbid + ' class="table table-hover"></table>');
			var myOpt = MyTable.getDefaultOptions();
			myOpt.scrollX = false;
			myOpt.autoWidth = false;
			myOpt.columnDefs = [ {
				"width" : "33%",
				"targets" : 0
			}, {
				"width" : "33%",
				"targets" : 1
			}, {
				"width" : "33%",
				"targets" : 2
			} ];
			myOpt.scrollY = 230;
			myOpt.scrollCollapse = true;
			var tab = new MyTable(tbid, columns, myOpt);
			tab.setDataSet(dataset);
			tab.show();
			tab.onRowClick(function(data) {
				if (data) {
					$("#input_search").val(data[searchIndex]);
					searchObj(true);
				}
			});
			return div;
		};
		this.commonNoData = function(parentDivId, infoDivId, title, info, expand, clickListener, subTitle, subTitleClick) {
			var div = drawTablePanel(parentDivId, title, infoDivId, expand, clickListener, subTitle, subTitleClick);
			div.append('<p class="text-success">' + info + '</p>');
			div.css('text-align', 'center');
			return div;
		};
		function drawTablePanel(parentDivId, title, tableId, expand, clickListener, subTitle, subTitleClick) {
			var collIn = "";
			if (expand) {
				collIn = " in ";
			}
			var sub = "";
			if (subTitle) {
				sub = '<span class="pull-right" onClick="'
					+ subTitleClick
					+ '" onMouseOver="this.style.textDecoration=\'underline\';this.style.cursor=\'pointer\';"'
					+ 'onMouseOut="this.style.textDecoration=\'none\';this.style.cursor=\'none\';"><small style="color:#A6A6A6" >'
					+ subTitle + '</small></span>';
			}
			var h = $('<div class="panel panel-default" style="margin:0">' + '<ul class="nav nav-pills nav-stacked">'
					+ '<li class="panel-title">' + '<a onclick=' + clickListener + ' data-parent="#' + parentDivId
					+ '" data-toggle="collapse" href="#' + tableId + 'Parent">' + title + sub + '</a>' + '</li>' + '</ul>'
					+ '</div>');
			var tabdiv = $('<div id="' + tableId + 'Parent" class="panel-collapse collapse ' + collIn + '">' + '</div>');
			$('#' + parentDivId).append(h);
			h.append(tabdiv);
			return tabdiv;
		}
		this.addNoInfo = function(text, div, clickListener) {
			$('#' + div).append(
					'<div onclick=' + clickListener + ' class="panel panel-default" style="margin:0;height:100px;">'
					+ '<div class="col-md-12" style="text-align:center;padding-top:20px;">'
					+ '<i class="fa fa-smile-o"  style="font-size:40px !important;color:green"></i>'
					+ '<p class="text-success">' + text + '</p>' + '</div>' + '</div>');
		};
		this.setSuccessBox = function() {
			var div = $('#' + divId);
			if (div.hasClass('box-danger')) {
				div.removeClass('box-danger');
				div.addClass('box-success');
			}
		};
		this.setDangerBox = function() {
			var div = $('#' + divId);
			if (div.hasClass('box-success')) {
				div.removeClass('box-success');
				div.addClass('box-danger');
			}
		};
		this.getNormalTimeStr = function(millis) {
			getNormalTimeStr(millis);
		};
		function getNormalTimeStr(millis) {
			if (!millis) {
				return "";
			}
			var s = "";
			var t = new Date(millis);
			var today = new Date();
			today.setHours(0);
			today.setMinutes(0);
			today.setSeconds(0);
			var todayMillis = today.getTime();
			var oneDayMillis = 24 * 60 * 60 * 1000;
			if (millis >= todayMillis && millis < todayMillis + oneDayMillis) {
				s += "今天";
			} else if (millis >= todayMillis - oneDayMillis && millis < todayMillis) {
				s += "昨天";
			} else if (millis >= todayMillis - 2 * oneDayMillis && millis < todayMillis - oneDayMillis) {
				s += "前天";
			} else {
				s += getDayTimeStr(millis);
			}
			var h = t.getHours() > 9 ? t.getHours() : "0" + t.getHours();
			var min = t.getMinutes() > 9 ? t.getMinutes() : "0" + t.getMinutes();
			var sec = t.getSeconds() > 9 ? t.getSeconds() : "0" + t.getSeconds();
			s += " " + h + ":" + min + ":" + sec;
			return s;
		}
		this.getSecondTimeStr = function(millis) {
			return getSecondTimeStr(millis);
		};
		function getSecondTimeStr(millis) {
			if (!millis) {
				return "";
			}
			var t = new Date(millis);

			var m = t.getMonth() + 1 > 9 ? (t.getMonth() + 1) : ("0" + (t.getMonth() + 1));
			var d = t.getDate() > 9 ? t.getDate() : "0" +t.getDate();
			var h = t.getHours() > 9 ? t.getHours() : "0" +t.getHours();
			var min = t.getMinutes() > 9 ? t.getMinutes() : "0" +t.getMinutes();
			var s = t.getSeconds() > 9 ? t.getSeconds() : "0" +t.getSeconds();
			var timestr = t.getFullYear() + "-" + m + "-" + d + " " +h + ":" + min + ":" + s;

			return timestr;
		}
		this.getDayTimeStr = function(millis) {
			return getDayTimeStr(millis);
		};
		/**
		 * 时间戳获取时间
		 */
		function getDayTimeStr(millis) {
			if (!millis) {
				return "";
			}
			var t = new Date(millis);
			var m = t.getMonth() + 1 > 9 ? (t.getMonth() + 1) : ("0" + (t.getMonth() + 1));
			var d = t.getDate() > 9 ? t.getDate() : "0" + t.getDate();
	 var timestr = t.getFullYear() + "-" + m + "-" + d;
			return timestr;
		}
		this.loadMapAndEquip = function(data, keyIndexArr, valueIndexObj, equipIndex) {
			// 若 keyIndexArr:[1,2] valueIndex:3 equipIndex 4
			// map组织成 key "data[i][1]+','+data[i][2]" value [data[i][3],...]
			// equipment 组织成 [data[i][4],...]
			var map = new Map();
			var equip = [];
			for ( var i in data) {
				equip.push(data[i][equipIndex]);
				var key = "";
				for ( var j in keyIndexArr) {
					key += data[i][keyIndexArr[j]] + ",";
				}
				key = key.substring(0, key.length - 1);
				var value = {};
				for ( var j in valueIndexObj) {
					value[j] = data[i][valueIndexObj[j]];
				}
				map.put(key, value);
			}
			return {
				map : map,
				equipment : equip
			};
		};
		this.getDataset = function(data, indexArr) {
			var dataset = [];
			for ( var i in data) {
				var d = [];
				for ( var j in indexArr) {
					var index = indexArr[j];
					var v = data[i][index.value ? index.value : index];
					if (v) {
						switch (index.type) {
						case 'dayTimeStr':
							d.push(getDayTimeStr(v.time ? v.time : v));
							break;
						case 'secondTimeStr':
							d.push(getSecondTimeStr(v.time ? v.time : v));
							break;
						default:
							d.push(v);
						}
					} else {
						d.push('');
					}
				}
				dataset.push(d);
			}
			return dataset;
		};
		this.openDialogWithTimeParamter = function(url, value) {
			var start = dailyFaultMan.getStart();
			var end = dailyFaultMan.getEnd();
			var params = '?startTime=' + start + '&endTime=' + end;
			if (value) {
				for ( var i in value) {
					params += "&" + i + "=" + value[i];
				}
			}
			if (url && url != "") {
				MyModal.showModal(url + params);
			}
		};
		this.openDialog = function(url, value) {
			if (url && url != "") {
				var params = '';
				if (value) {
					params += "?";
					for ( var i in value) {
						params += i + "=" + value[i] + "&";
					}
					params = params.substring(0, params.length - 1);
				}
				MyModal.showModal(url + params);
			}
		};
		this.getGif = function(type) {
			return '/resources/img/daily/' + type + '.gif';
		};
	}
}
